//
//  HTPremiumScreen.swift
//  MagaCore
//
//  Created by MrMessy on 2023/4/29.
//

import SwiftUI

struct HTPremiumScreen: View {

  @EnvironmentObject private var var_store: HTAppStore
  @State var var_isPush: Bool = false
  @State var var_curSubscribe: HTSubscribe?

  var body: some View {
    VStack{
      HTNavigationBar{
        VStack(alignment: .leading, spacing: 0){
          ScrollView(showsIndicators: false){
            VStack(spacing: 0){
              if (var_curSubscribe != nil) {
                Spacer().frame(height: 15)
                HTPremiumPlanSection(var_curSubscribe: $var_curSubscribe)
                Spacer().frame(height: 15)
                HTPremiumFollowSection()
              }

              Spacer().frame(height: 25)
              HTPremiumAccessSection()
              Spacer().frame(height: 15)
              HTPremiumPackageSection()

              Divider()
                .padding(.top, 30)
                .padding(.bottom, 20)

              HTPremiumTipSection()
            }
            .padding(.horizontal, 15)
          }
          .frame(maxWidth: .infinity)

          Spacer()

          HTPremiumPaySection()
        }
        .background(Color(hex: "#f5f5f5"))
        .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)
        .padding(.bottom, var_isPush ? UIDevice.ht_tabBarHeight() :  UIDevice.ht_tabBarFullHeight())
      }
      .ht_title(title: "Premium")
      .ht_backButtonHidden(var_isPush ? false : true)
    }
    .frame(maxWidth: .infinity, maxHeight: .infinity)
    .background(Color.white)
    .ignoresSafeArea()
    .onAppear{
      var_curSubscribe = var_store.state.var_subscribeState.var_curSubscribe ?? nil
      HTNetworkManager().ht_requestForBuried(.htEnumVipSh(var_source: "7"))
    }
    .onReceive(var_store.objectWillChange) { _ in
      var_curSubscribe = var_store.state.var_subscribeState.var_curSubscribe ?? nil
    }
  }
}
